//
//  WHMainTabarView.swift
//  WHSinaWeiBo
//
//  Created by 王寒 on 16/4/6.
//  Copyright © 2016年 wanghan. All rights reserved.
//

import UIKit

class WHMainTabarView: UITabBar {


    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(plusBtn)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()

        //设置尺寸
        let btnWidth = self.frame.width / 5
        let btnHeight = self.frame.height
        let rect = CGRectMake(0, 0, btnWidth, btnHeight)
        var index: CGFloat = 0
        
        for subView in subviews{
            
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){
               subView.frame = CGRectOffset(rect, index * btnWidth, 0)
                
                 index += (index == 1) ? 2 : 1
                
            }
            
        }
        plusBtn.frame = CGRectMake(btnWidth * 2, 0, btnWidth, btnHeight)
        
        //拓展
//        plusBtn.frame = CGRectMake(btnWidth * 2, -10, btnWidth, btnHeight)
//        bringSubviewToFront(plusBtn)
    }
    
                
            


    //懒加载加载按钮
    private lazy var plusBtn: UIButton = {
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Selected)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Selected)
        
        
        return btn
    }()

}
